<script setup>
import {ref,onMounted} from 'vue'
import { detailGetGoodsHotdata } from '@/apis/detail'
import { useRoute } from 'vue-router'
const route = useRoute()
const props = defineProps({
  title:{
    type:String
  },
  goodsType:{
    type:Number
  }
})
// 获取商品热榜数据
// 查询参数数据
const paramsData = ref({
  /**
 * 获取热榜商品
 * @param {Number} id - 商品id
 * @param {Number} type - 1代表24小时热销榜 2代表周热销榜
 * @param {Number} limit - 获取个数
 */
  id:route.params.id,
  type:props.goodsType,
  limit:3
})
const goodsHot = ref([])
const getGoodsHot = async ()=>{
  const res = await detailGetGoodsHotdata(paramsData)
  goodsHot.value = res.data.result
}
onMounted(()=>getGoodsHot())
</script>


<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <!-- 商品区块 -->
    <RouterLink :to="`/detail/${item.id}`" class="goods-item" v-for="item in goodsHot" :key="item.id">
      <img :src="item.picture" alt="" />
      <p class="name ellipsis">{{ item.name }}</p>
      <p class="desc ellipsis">{{item.desc}}</p>
      <p class="price">&yen;{{item.price}}</p>
    </RouterLink>
  </div>
</template>


<style scoped lang="scss">
.goods-hot {
  h3 {
    height: 70px;
    background: $helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }

  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    width: 280px;

    img {
      width: 160px;
      height: 160px;
    }

    p {
      padding-top: 10px;
    }

    .name {
      font-size: 16px;
    }

    .desc {
      color: #999;
      height: 29px;
    }

    .price {
      color: $priceColor;
      font-size: 20px;
    }
  }
}
</style>
